<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"  xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="utf-8" >
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>招商项目库</title>
    <link rel="stylesheet" th:href="@{/myconfig/layui/css/layui.css}" href="../static/myconfig/layui/css/layui.css" media="all">
    <style>
        body{margin: 10px;}
        .demo-carousel{height: 200px; line-height: 200px; text-align: center;}
    </style>
</head>
<body>

<table class="layui-hide" id="demo" lay-filter="test" lay-data="{id: 'idTest'}"></table>

<script th:src="@{/myconfig/layui/layui.js}" src="../static/myconfig/layui/layui.js"></script>

<script type="text/html" id="mytoolbar">
    <div class="layui-table-tool-temp" style="height: 50px;min-width: 1300px;">
        <div class="layui-form-item">
            <form class="layui-form" action="">
                <div class="layui-input-block" style="margin: 0 0 0 5px;width: 20%;float: left;">
                    <input shiro:hasPermission="businessProject_listBusinessprojects" type="text" name="projectName" lay-verify="title" autocomplete="off" placeholder="请输入项目名" class="layui-input">
                </div>
                <div style="float: left">
                    <div class="layui-inline">
                        <div class="layui-input-inline" style="margin-left: 10px;width: 100px;" >
                            <select shiro:hasPermission="businessProject_searchBusinessproject" name="businessProjectCountyId"  lay-search="">
                                <option value="">县区分类</option>
                                <option value="1">柳城县</option>
                                <option value="2">鹿寨县</option>
                                <option value="3">融安县</option>
                                <option value="4">融水苗族自治县</option>
                                <option value="5">三江侗族自治县</option>
                            </select>
                        </div>
                        <div class="layui-input-inline" style="width: 100px;">
                            <select shiro:hasPermission="businessProject_searchBusinessproject" name="industryTypeId" lay-search="">
                                <option value="">行业分类</option>
                                <option value="1">养殖业</option>
                                <option value="2">畜牧业</option>
                                <option value="3">房地产业</option>
                                <option value="4">旅游业</option>
                                <option value="5">服务业</option>
                            </select>
                        </div>
                        <div class="layui-input-inline" style="width: 100px;">
                            <select shiro:hasPermission="businessProject_searchBusinessproject" name="projectStatusId" lay-search="">
                                <option value="">状态分类</option>
                                <option value="1">立项状态</option>
                                <option value="2">项目执行</option>
                                <option value="3">项目完工</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div style="float: left">
                    <button shiro:hasPermission="businessProject_searchBusinessproject" class="layui-btn layui-btn-normal" lay-submit lay-filter="formSearch">搜索项目</button>
                </div>
            </form>
            <div style="margin-left: 15px;float: left">
                <button shiro:hasPermission="businessProject_addBusinessproject" class="layui-btn layui-btn-warm" lay-event="add" data-method="setTop">
                    <i class="layui-icon">&#xe654;</i>添加项目</button>
                <button shiro:hasPermission="businessProject_updateBusinessproject" class="layui-btn layui-btn-warm" lay-event="update">
                    <i class="layui-icon">&#xe642;</i>修改信息</button>
                <button shiro:hasPermission="businessProject_deleteBusinessproject" class="layui-btn layui-btn-danger" lay-event="delete">
                    <i class="layui-icon">&#xe640;</i>删除项目</button>
            </div>
        </div>

    </div>
</script>

<script type="text/html" id="barDemo">
    <a shiro:hasPermission="businessProject_checkBusinessproject" class="layui-btn layui-btn-warm layui-btn-sm" lay-event="check">审核</a>
    <button shiro:hasPermission="businessProject_uploadBusinessproject" type="button" class="layui-btn layui-btn-warm layui-btn-sm" lay-event="upload" id="test3"><i class="layui-icon"></i>上传附件</button>
</script>

<script th:inline="none">

    layui.config({
        version: '1554901098009' //为了更新 js 缓存，可忽略
    });

    layui.use(['laydate', 'laypage', 'layer', 'table', 'carousel', 'upload', 'element', 'slider', 'upload'], function(){
        var  laypage = layui.laypage //分页
            ,table = layui.table //表格
            ,form = layui.form
            ,upload = layui.upload;
        //执行一个 table 实例
        var $ = layui.$;


        $.ajax({
            type: "post",
            url: 'businessProject/list' //数据接口
            ,success: function (result) {
                data = result.data;
                table.render({
                    elem: '#demo'
                    ,unresize: false
                    ,height: 630
                    ,id: 'idTest'
                    ,title: '项目表'
                    ,toolbar: '#mytoolbar' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
                    ,data: data
                    ,cols: [[
                        {type: 'checkbox', fixed: 'left'}
                        ,{field: 'businessProjectId', title: '招商项目ID', width:70, sort: true,unresize: false}
                        ,{field: 'projectName', title: '项目名称', width:150,sort: true,unresize: false}
                        ,{field: 'projectContent', title: '项目内容', width:270}
                        ,{field: 'projectTime', title: '项目创建时间', width:130,unresize: false, sort: true}
                        ,{field: 'countyName', title: '区县', width: 130,unresize: false, sort: true}
                        ,{field: 'industryName', title: '行业', width: 100, sort: true,unresize: false, sort: true}
                        ,{field: 'projectStatusName', title: '项目状态', width: 130, sort: true,unresize: false}
                        ,{field: 'statusName', title: '状态', width: 135,unresize: false, sort: true}
                        ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:180}
                    ]] //设置表头
                    ,page:{theme: '#1E9FFF'}
                    ,limits: [5, 10, 15,20] //每页显示个数
                    ,limit: 10 //每页默认显示的数量
                    ,group:5   //页码最多显示个数
                });
            }
        });

        form.on('submit(formSearch)',function (data) {
            $.ajax({
                type: "post",
                url: 'businessProject/search' //数据接口
                ,data:data.field
                ,success: function (result) {
                    data = result.data;
                    table.render({
                        elem: '#demo'
                        ,unresize: false
                        ,height: 630
                        ,id: 'idTest'
                        ,title: '项目表'
                        ,toolbar: '#mytoolbar' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
                        ,data: data
                        ,cols: [[
                            {type: 'checkbox', fixed: 'left'}
                            ,{field: 'businessProjectId', title: '招商项目ID', width:70, sort: true,unresize: false}
                            ,{field: 'projectName', title: '项目名称', width:150,sort: true,unresize: false}
                            ,{field: 'projectContent', title: '项目内容', width:270}
                            ,{field: 'projectTime', title: '项目创建时间', width:130,unresize: false, sort: true}
                            ,{field: 'countyName', title: '区县', width: 130,unresize: false, sort: true}
                            ,{field: 'industryName', title: '行业', width: 100, sort: true,unresize: false, sort: true}
                            ,{field: 'projectStatusName', title: '项目状态', width: 130, sort: true,unresize: false}
                            ,{field: 'statusName', title: '状态', width: 135,unresize: false, sort: true}
                            ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:180}
                        ]] //设置表头
                        ,page:{theme: '#1E9FFF'}
                        ,limits: [5, 10, 15,20] //每页显示个数
                        ,limit: 10 //每页默认显示的数量
                        ,group:5   //页码最多显示个数
                    });
                }
            })
            return false;
        })

        //监听行工具事件
        table.on('tool(test)', function(obj){
            switch (obj.event){
                case 'check':
                    layer.open({
                        type: 2 //此处以iframe举例
                        ,title: '审核招商项目'
                        ,area: ['600px', '550px']
                        ,shade: 0
                        ,resize: false
                        ,moveOut: true
                        ,maxmin: true
                        ,content: 'business_project_index_check.html'
                        ,zIndex: layer.zIndex //重点1
                        ,success: function(layero, index){
                            var iframe = window['layui-layer-iframe' + index];
                            iframe.init(obj.data.businessProjectId);
                        }
                        ,end:function () {
                            $.ajax({
                                type: "post",
                                url: 'businessProject/list' //数据接口, // 数据接口
                                ,success: function (result) {
                                    data = result.data;
                                    table.render({
                                        elem: '#demo'
                                        ,unresize: false
                                        ,height: 630
                                        ,id: 'idTest'
                                        ,title: '项目表'
                                        ,toolbar: '#mytoolbar' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
                                        ,data: data
                                        ,cols: [[
                                            {type: 'checkbox', fixed: 'left'}
                                            ,{field: 'businessProjectId', title: '招商项目ID', width:70, sort: true,unresize: false}
                                            ,{field: 'projectName', title: '项目名称', width:150,sort: true,unresize: false}
                                            ,{field: 'projectContent', title: '项目内容', width:270}
                                            ,{field: 'projectTime', title: '项目创建时间', width:130,unresize: false, sort: true}
                                            ,{field: 'countyName', title: '区县', width: 130,unresize: false, sort: true}
                                            ,{field: 'industryName', title: '行业', width: 100, sort: true,unresize: false, sort: true}
                                            ,{field: 'projectStatusName', title: '项目状态', width: 130, sort: true,unresize: false}
                                            ,{field: 'statusName', title: '状态', width: 135,unresize: false, sort: true}
                                            ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:180}
                                        ]] //设置表头
                                        ,page:{theme:'#1E9FFF'}
                                        ,limits: [5, 10, 15,20] //每页显示个数
                                        ,limit: 10 //每页默认显示的数量
                                        ,group:5   //页码最多显示个数
                                    });
                                }
                            });
                        }
                    });
                    break;
                case 'upload':
                    layer.open({
                        type: 2 //此处以iframe举例
                        ,title: '文件上传'
                        ,area: ['600px', '500px']
                        ,shade: 0
                        ,maxmin: true
                        ,content: 'file_manage_upload_business_project.html'
                        ,zIndex: layer.zIndex //重点1
                        ,success: function(layero, index){
                            var iframe = window['layui-layer-iframe' + index];
                            iframe.init(obj.data.businessProjectId);
                        }
                    });
            }
        });

        //监听头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id)
                ,data = checkStatus.data; //获取选中的数据
            switch(obj.event){
                case 'add':
                    layer.open({
                        type: 2 //此处以iframe举例
                        ,title: '添加招商项目'
                        ,area: ['600px', '550px']
                        ,shade: 0
                        ,resize: false
                        ,moveOut: true
                        ,maxmin: true
                        ,content: 'business_project_index_add.html'
                        ,zIndex: layer.zIndex //重点1
                        ,success: function(layero, index){
                            // console.log(layero, index);
                        }
                        ,end:function () {
                            $.ajax({
                                type: "post",
                                url: 'businessProject/list' //数据接口, // 数据接口
                                ,success: function (result) {
                                    data = result.data;
                                    table.render({
                                        elem: '#demo'
                                        ,unresize: false
                                        ,height: 630
                                        ,id: 'idTest'
                                        ,title: '项目表'
                                        ,toolbar: '#mytoolbar' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
                                        ,data: data
                                        ,cols: [[
                                            {type: 'checkbox', fixed: 'left'}
                                            ,{field: 'businessProjectId', title: '招商项目ID', width:70, sort: true,unresize: false}
                                            ,{field: 'projectName', title: '项目名称', width:150,sort: true,unresize: false}
                                            ,{field: 'projectContent', title: '项目内容', width:270}
                                            ,{field: 'projectTime', title: '项目创建时间', width:130,unresize: false, sort: true}
                                            ,{field: 'countyName', title: '区县', width: 130,unresize: false, sort: true}
                                            ,{field: 'industryName', title: '行业', width: 100, sort: true,unresize: false, sort: true}
                                            ,{field: 'projectStatusName', title: '项目状态', width: 130, sort: true,unresize: false}
                                            ,{field: 'statusName', title: '状态', width: 135,unresize: false, sort: true}
                                            ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:180}
                                        ]] //设置表头
                                        ,page:{theme:'#1E9FFF'}
                                        ,limits: [5, 10, 15,20] //每页显示个数
                                        ,limit: 10 //每页默认显示的数量
                                        ,group:5   //页码最多显示个数
                                    });
                                }
                            });
                        }
                    });
                    break;
                case 'update':
                    if(data.length === 0){
                        layer.msg('请选择要修改的项目',{
                            icon:0
                        });
                    } else if(data.length > 1){
                        layer.msg('只能同时修改一个项目',{
                            icon:0
                        });
                    } else {
                        // layer.alert('编辑 [id]：'+ checkStatus.data[0].businessProjectId);
                        layer.open({
                            type: 2 //此处以iframe举例
                            ,title: '修改招商项目'
                            ,area: ['600px', '550px']
                            ,shade: 0
                            ,resize: false
                            ,moveOut: true
                            ,maxmin: true
                            ,content: 'business_project_index_update.html'
                            ,zIndex: layer.zIndex //重点1
                            ,success: function(layero, index){
                                var iframe = window['layui-layer-iframe' + index];
                                iframe.init(checkStatus.data[0].businessProjectId);
                            }
                            ,end:function () {
                                $.ajax({
                                    type: "post",
                                    url: 'businessProject/list' //数据接口, // 数据接口
                                    ,success: function (result) {
                                        data = result.data;
                                        table.render({
                                            elem: '#demo'
                                            ,unresize: false
                                            ,height: 630
                                            ,id: 'idTest'
                                            ,title: '项目表'
                                            ,toolbar: '#mytoolbar' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
                                            ,data: data
                                            ,cols: [[
                                                {type: 'checkbox', fixed: 'left'}
                                                ,{field: 'businessProjectId', title: '招商项目ID', width:70, sort: true,unresize: false}
                                                ,{field: 'projectName', title: '项目名称', width:150,sort: true,unresize: false}
                                                ,{field: 'projectContent', title: '项目内容', width:270}
                                                ,{field: 'projectTime', title: '项目创建时间', width:130,unresize: false, sort: true}
                                                ,{field: 'countyName', title: '区县', width: 130,unresize: false, sort: true}
                                                ,{field: 'industryName', title: '行业', width: 100, sort: true,unresize: false, sort: true}
                                                ,{field: 'projectStatusName', title: '项目状态', width: 130, sort: true,unresize: false}
                                                ,{field: 'statusName', title: '状态', width: 135,unresize: false, sort: true}
                                                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:180}
                                            ]] //设置表头
                                            ,page:{theme:'#1E9FFF'}
                                            ,limits: [5, 10, 15,20] //每页显示个数
                                            ,limit: 10 //每页默认显示的数量
                                            ,group:5   //页码最多显示个数
                                        });
                                    }
                                });
                            }
                        });
                    }
                    break;
                case 'delete':
                    if(data.length === 0){
                        layer.msg('请选择要删除的项目',{
                            icon:0
                        });
                    } else {
                        layer.confirm('确定删除该项目吗？', function(index){
                            var deletelist = [];
                            for (var i = 0;i < checkStatus.data.length;i++){
                                deletelist[i] = checkStatus.data[i].businessProjectId
                            }
                            //向服务端发送删除指令
                            $.ajax({
                                url:'businessProject/delete'
                                ,data:{'deletelist':deletelist}
                                ,success:function (result) {
                                    if (result.code == 200){
                                        layer.msg("删除成功",{
                                            icon:6
                                        })
                                        setTimeout("window.location.reload()",1000);
                                    } else{
                                        layer.msg("删除失败"),{
                                            icon:5
                                        }
                                    }
                                }
                            })
                        });
                    }
                    break;
            };
        });
    });
</script>
</body>
</html>
